﻿using System;
using System.Collections;
using System.Collections.Generic;
using Gp.GCX;
using Gp.Scripts.Core;
using Helpers;
using QFSW.QC;
using QFSW.QC.Actions;

// ReSharper disable ExplicitCallerInfoArgument
namespace Gp.Scripts.Console {
    [CommandPrefix("basic.")]
    public static class ConsoleApiBasic {
        [Command("save")]
        public static void Save() {
            Global.Get<SaveManager>().SaveGame();
        }

        [Command("load")]
        public static IEnumerator<ICommandAction> Load() {
            yield return new Choice<string>(Global.Get<SaveManager>().GetSaveFiles(),
                s => Global.Get<SaveManager>().LoadGame(s));
        }


        [Command("runSpeed")]
        public static void SetSpeed(int speed) {
            if (ObjectHelper.PlayerCharacter) {
                ObjectHelper.PlayerCharacter.SetRunSpeed(speed);
            }
        }


        [Command("skipBattle")]
        public static void SkipBattle(bool status = true) {
            if (status) MainArchitecture.Interface.RegisterEvent<Event_BattleStart>(SkipProcess);
            else MainArchitecture.Interface.UnRegisterEvent<Event_BattleStart>(SkipProcess);


            void SkipProcess(Event_BattleStart args) {
                try {
                    MainArchitecture.Interface.SendCommand(new BattleEndCommand(Global.Get<BattleSystem>().BattleSettle));
                }
                catch (Exception _) {
                    // ignored
                }
            }
        }
    }
}